/**
 * Created by Administrator on 2017/1/16.
 */

var MJPlayer = require('../MJ/player').MJPlayer;
var MJ = require('../MJ/MJ');
var Const = require('./const');
var SubCode = require('../subCode');

exports.LFMJPlayer = MJPlayer.extend({
    /****
    *****
     this._stat.roundResult = 0;         // 本轮结果  DRAW: 0,平局   DH: 1,点胡    ZM: 2 自摸
     this._stat.roundTarget = [];        // 本轮管住的人坐位列表，将向它们收取（牌型分+其它分）
     this._stat.roundPattern = 0;        // 本轮牌型，胡牌者为胡牌的牌型，未胡者为最大听牌牌型//(只有一个
     this._stat.roundPatternScore = 0;   // 本轮牌型分
     this._stat.roundGangScore = 0;      // 本轮杠分
     this._stat.roundItemScores = {};    // 本轮其它分----->客户端显示。。牌型？+规则+杠分+其他特殊分
     this._stat.roundScoreRules = {};    // 本轮计分规则(用于标注发生了什么特殊规则)//用于算分，可叠加，最后的得分为规则分加起来，k为规则，v为分数
     this._stat.roundScoreDetails = [];  // 本局积分详情{reason:0, score:0}
    *****
    *****/
    _huInfo: {},
    init: function(uid, msg) {
        this._super(uid, msg);
        this._stat.zmCount = 0;             // 自摸次数
        this._stat.dpCount = 0;             // 点炮次数
        this._stat.dhCount = 0;             // 点胡次数
        this._stat.anGangCount = 0;        // 暗杠次数
        this._stat.mingGangCount = 0;      // 明杠次数
        this._stat.lzCount = 0;             // 庄家次数
        this._stat.roundRules = {};         //规则（本轮有哪些规则
        this._handCardsHuInfo = {};
        /**
         * k:color
         *v:
         * {
         *  change: true/false, 该颜色的牌是否改变
         *  hu: true/false,     是否能组成胡牌(3X/3X2)
         *  jiang: 0,           将牌
         *  ting: [
         *  {
         *      card,
         *      jiang
         *  }
         *  ],           可以胡的牌
         * }
         *
         * */
        this._huInfo = {
            /*
            *
            * pattern 当前牌型
            * jiang 将牌
            * jiangs 听牌时可能的将牌
            * */
            pattern: 0,
            jiang: 0,
            jiangs: {}
        };

    },
    settlementRules: function(){
        var pattern = this.getRoundPattern();
        var gapInfo = this.checkGap();
        var tempRule = 0;
        var room = this.getRoom();
        var player = this;
        var cards = player.getHandCards();
        if(gapInfo.colorNum == 0 && gapInfo.zi == true){
            player.setRoundScoreRule(Const.ScoreRule.ZiYiSe);
        }else if(gapInfo.colorNum == 1 && gapInfo.zi == false){
            player.setRoundScoreRule(Const.ScoreRule.QingYiSe);
        }
        if(this.checkYTL(cards)){
            player.setRoundScoreRule(Const.ScoreRule.YiTiaoLong);
        }
        logger.debug("room = %d, index = %d, pattern = %d, rule = %j", room.rid(), player.getIndex(), player._stat.roundScoreRules);
        switch (pattern){
            case Const.Pattern.H2PAIR7:
                tempRule = Const.ScoreRule.H2Pair7;
                this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                return;
                break;
            case Const.Pattern.H1PAIR7:
                if(player.existRoundScoreRule(Const.ScoreRule.QingYiSe)){
                    tempRule = Const.ScoreRule.QingYiSeH1Pair7;
                    this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                    return;
                }
                tempRule = Const.ScoreRule.H1Pair7;
                this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                break;
            case Const.Pattern.PAIR7:
                if(player.existRoundScoreRule(Const.ScoreRule.ZiYiSe)){
                    tempRule = Const.ScoreRule.ZiYiSePair7;
                    this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                    return;
                }
                if(player.existRoundScoreRule(Const.ScoreRule.QingYiSe)){
                    tempRule = Const.ScoreRule.QingYiSePair7;
                    this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                    return;
                }
                tempRule = Const.ScoreRule.Pair7;
                this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                break;
            case Const.Pattern.SINGLE:
            case Const.Pattern.NORMAL:
            case Const.Pattern.PAIR:
                if(player.existRoundScoreRule(Const.ScoreRule.QingYiSe) && player.existRoundScoreRule(Const.ScoreRule.YiTiaoLong)){
                    tempRule = Const.ScoreRule.QingYiSeYiTiaoLong;
                    this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                    return;
                }
                if(player.existRoundScoreRule(Const.ScoreRule.ZiYiSe)){
                    tempRule = Const.ScoreRule.ZiYiSe;
                    this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                    return;
                }
                if(player.existRoundScoreRule(Const.ScoreRule.QingYiSe)){
                    tempRule = Const.ScoreRule.QingYiSe;
                    this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                    break;
                }
                if(player.existRoundScoreRule(Const.ScoreRule.YiTiaoLong)){
                    tempRule = Const.ScoreRule.YiTiaoLong;
                    this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
                    break;
                }
                break;
            case Const.Pattern.NONE:
                logger.debug("!!!!!!!!!!!!! error pattern = 0 !!!!!!!!!!!!!");
                break;
        }
        var sanYuan = this.checkSanYuan();
        tempRule = Const.SanYuan[sanYuan];
        this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);

        var sanFeng = this.checkSanFeng();
        tempRule = Const.SanYuan[sanFeng];
        this.addRoundItemScores(tempRule, Const.ZMSanYuan[sanFeng]);

        tempRule = Const.Gap[player.getGap()];
        this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);

        if(this.checkGuJiang()){
            tempRule = Const.ScoreRule.GuJiang;
            this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
        }
        if(this.checkYZY()){
            tempRule = Const.ScoreRule.YiZhangYing;
            this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
        }
        if(this.checkMenQing()){
            tempRule = Const.ScoreRule.MenQing;
            this.addRoundItemScores(tempRule, Const.ItemScore[tempRule]);
        }

    },

    settlement: function() {

        if (this._stat.roundResult == MJ.Result.ZM) {
            this._stat.zmCount++;
        } else if (this._stat.roundResult == MJ.Result.DH) {
            this._stat.dhCount++;
            if (this._stat.roundTarget.length > 0) {
                var dpPlayer = this.getRoom().getPlayerByIndex(this._stat.roundTarget[0]);
                if (dpPlayer) {
                    dpPlayer._stat.dpCount++;
                }
            }
        }
        if (this.isDealer()) {
            this._stat.lzCount++;
        }
    },

    /******************************************************************
     * 重载的接口
     ******************************************************************/
    //断线重连信息
    getReconnectInfo: function(isSelf) {
        var info = this._super(isSelf);
        info.remainScore = this._stat.score;

        return info;
    },

    getSettlementInfo: function() {
        var info = this._super();
        info.gangCards = this._gangCards;
        info.pengCards = this._pengCards;
        info.chiCards = this._chiCards;
        info.handCards = this._handCards.getCards();
        info.remainScore = this._stat.score;
        info.gang = this._gangCards;
        return info;
    },

    onStartNewRound: function() {
        this._super();
        this._stat.roundRules = {};
        this._huInfo = {
            pattern: 0,
            jiang: 0
        };
    },

    getInitHandCardPreCards: function() {
        var room = this.getRoom();
        var preCards = [];

        var distance = this.getRoom().getIndexDistance(this.getIndex(), this.getRoom().getDealerIndex());
        if (distance == 0) {

        } else if (distance == 3) {

        }else if (distance == 1) {

        }
        return preCards;
    },

    /*checkTingOrHuCondition: function(){
        var room = this.getRoom();
        var count = this._super();
        if(count){
            if(room.getOption("MS") == "YSZ") {
                if (this.getCurFan() < 3) {
                    return false;
                }else {
                    return true;
                }
            }else if(room.getOption("MS") == "YMP") {
                if (this.getColorNum() > 1) {
                    return false;
                } else {
                    return true;
                }
            }else{
                logger.debug("error = %j ", room.getOption("MS"));
            }
        }else{
            return false;
        }
    },*/
    checkHuLogic: function(cards, huCard) {
        var num4 = 0;
        var num3 = 0;
        var num2 = 0;
        var num = 0;

        ExObject.each(cards, function(c, n) {
            if (n == 2) {
                num2++;
            } else if (n == 3) {
                num3++;
            } else if (n == 4) {
                num4++;
            }
            num += n;
        });

        if (num == 2) { // 单调
            return (num2 == 1) ? MJ.Pattern.SINGLE : MJ.Pattern.NONE;
        }

        if ((num2 + num4*2) == 7) { // 七对
            if(num4 == 1){
                return Const.Pattern.H1PAIR7;
            }else if(num4 > 1){
                return Const.Pattern.H2PAIR7;
            }
            return MJ.Pattern.PAIR7;
        }

        if (num2 == 1 && (num3*3 + 2) == num) { // 大对子
            return MJ.Pattern.PAIR;
        }
        var player = this;
        var room = this.getRoom();
        var colors = room.getSubConfig().colors;
        player._huInfo.jiang = 0;
        var pattern = MJ.Pattern.NORMAL;
        for (var i = 0, l = colors.length; i < l; ++i) {
            var color = colors[i];
            var colorCards = MJ.getColorCards(cards, color);

            if (MJ.isBasicColor(color)) {
                if (!this.checkHuColorCards(MJ.getValue(color, 1), MJ.getValue(color, MJ.COLOR_CARD_NUM), colorCards)) {
                    pattern = MJ.Pattern.NONE; break;
                }
            } else {
                if (this.checkHuZiCards(colorCards) < 0) {
                    pattern = MJ.Pattern.NONE; break;
                }
            }
        }
        if( pattern == MJ.Pattern.NONE){
            player._huInfo.jiang = 0;
        }

        return pattern;
    },
    checkHuColorCards: function(minCard, maxCard, colorCards) {
        var colorCardsNum = MJ.sumCardsNum(colorCards);
        if (colorCardsNum == 0) {
            return true;
        }

        var context = {result: false};
        var modNum = colorCardsNum % 3;
        if (modNum == 0) {
            MJ.checkHu3X(minCard, maxCard, colorCards, context);
        } else if (modNum == 2) {
            this.checkHu3X2(minCard, maxCard, colorCards, context);
        }

        return context.result
    },
    checkHu3X2: function(minCard, maxCard, cards, context) {
        if(this._huInfo.jiang){
            return false;
        }
        for (var i = minCard; i <= maxCard; ++i) {
            var num = cards[i];
            if (num >= 2) {
                var newCards = clone(cards);
                newCards[i] = num - 2;
                MJ.checkHu3X(minCard, maxCard, newCards, context);
                if (context.result){
                    this._huInfo.jiang = i;
                    break;
                }
            }
        }
    },
    checkTing: function() {
        var tings = [];

        if (!this.checkTingOrHuCondition()) {
            return tings;
        }
        var subConfig = this.getRoom().getSubConfig();
        var cards = this._handCards.getCards();
        subConfig.colors.forEach(function(color) {
            if (color == this.getSelectColor()) {
                return;
            }
            var cardNum = MJ.ColorCardNum[color];
            for (var p = 1, pm = cardNum.point; p <= pm; ++p) {
                var card = MJ.getValue(color, p);
                if (cards[card] === 4) {
                    continue;
                }
                var tmpCards = clone(cards);
                ExObject.addNumber(tmpCards, card, 1);
                var pattern = this.checkHuLogic(tmpCards, card);
                if (pattern != MJ.Pattern.NONE) {
                    tings.push({card: card, pattern: pattern});
                    this._huInfo.jiangs[this._huInfo.jiang] = 1;
                }
            }
        }.bind(this));
        return tings;
    },
    checkHuLogicNew: function(color){
        var cards = this.getHandCards();
        var colorCards = MJ.getColorCards(cards, color);
        var colorCardsNum = ExObject.sumValue(colorCards);
        var player = this;
        var room = this.getRoom();
        if(colorCardsNum == 0){
            player._handCardsHuInfo[color] = {
                hu: true,
                change: false,
                jiang: 0,
                ting: []
            };
            return;
        }
        if (MJ.isBasicColor(color)) {
            if (this.checkHuColorCardsNew()) {

            }
        } else {
            if (this.checkHuZiCards(colorCards) < 0) {
                player._handCardsHuInfo[color] = {
                    hu: false,
                    change: false,
                    jiang: 0,
                    ting: []
                };
            }
        }
        return;
    },
    checkHuColorCardsNew: function(cards){
        var colorCardsNum = MJ.sumCardsNum(cards);
        if (colorCardsNum == 0) {
            return true;
        }
        var context = {result: false};
        var modNum = colorCardsNum % 3;
        if (modNum == 0) {
            MJ.checkHu3X(MJ.getValue(color, 1), MJ.getValue(color, MJ.COLOR_CARD_NUM), cards, context);
        } else if (modNum == 2) {
            MJ.checkHu3X2(MJ.getValue(color, 1), MJ.getValue(color, MJ.COLOR_CARD_NUM), cards, context);
        }
        return context.result
    },
    /**
     * 玩家字牌胡牌
     * @param cards 字牌对象
     * @return {number} 将牌牌值 -1不能构成胡牌，0没有将牌，
     *
     */
    checkHuZiCards: function(cards){
        var colorCardsNum = ExObject.sumValue(cards);
        if (colorCardsNum == 0) {
            return 0;
        }
        var fengCards = {};
        var yuanCards = {};
        ExObject.eachKeyNum(cards, function(c, n) {
            if (c > MJ.ZI.BF) {
                yuanCards[c] = n;
            } else {
                fengCards[c] = n;
            }
        });
        var fengCardsNum = ExObject.sumValue(fengCards);
        var yuanCardsNum = ExObject.sumValue(yuanCards);
        var fengMod = fengCardsNum % 3;
        var yuanMod = yuanCardsNum % 3;
        var resp = 0;
        var huFeng = false;
        var huYuan = false;

        if(fengMod == 0){
            huFeng = this.checkHuFengCards3X(fengCards);
        }else if(fengMod == 2){
            ExObject.eachKeyNum(fengCards, function(c, n){
                if(huFeng){
                    return;
                }
                if(n > 1){
                    var newCards = clone(fengCards);
                    newCards[c] -= 2;
                    if(this.checkHuFengCards3X(newCards)){
                        huFeng = true;
                        resp = c;
                    }
                }
            }.bind(this));
        }

        if(yuanMod == 0){
            huYuan = this.checkHuYuanCards3X(yuanCards);

        }else if(yuanMod == 2){
            ExObject.eachKeyNum(yuanCards, function(c, n){
                if(huYuan){
                    return;
                }
                if(n > 1){
                    var newCards = clone(yuanCards);
                    newCards[c] -= 2;
                    if(this.checkHuFengCards3X(newCards)){
                        huYuan = true;
                        resp = c;
                    }
                }
            }.bind(this));
        }
        if(huYuan != true || huFeng != true){
            resp = -1;
        }
        return resp;
    },
    checkHuFengCards3X: function(cards){
        var colorCardsNum = ExObject.sumValue(cards);
        var sanFeng = this.checkSanFeng(cards);
        logger.debug("sanFeng = %d, cardsNum = %d", colorCardsNum, sanFeng);
        var num = colorCardsNum / 3;

        return (sanFeng == num);
    },
    checkHuYuanCards3X: function(cards){
        var colorCardsNum = ExObject.sumValue(cards);
        var sanYuan = this.checkSanFeng(cards);
        logger.debug("sanYuan = %d, cardsNum = %d", colorCardsNum, sanYuan);
        var num = colorCardsNum / 3;

        return (sanYuan == num);
    },



    /******************************************************************
     * 功能的接口
     ******************************************************************/
    /**
     * 
     *
     */
    //获取当前嘴
    getCurFan: function(){
        var num = 0;
        var gap = this.getGap();

        num += Const.ItemScore[Const.Gap[gap]];
        if(this.checkYZY()){
            num += 1;
        }
        if(this.checkGuJiang(this._huInfo)){
            num += 1;
        }
        num += Const.ItemScore[Const.SanFeng[this.checkSanFeng()]];
        num += Const.ItemScore[Const.SanYuan[this.checkSanYuan()]];
        return num;
    },
    //获取听牌的嘴
    getTingFan: function(){
        var num = 0;
        var gap = this.getGap();

        num += Const.ItemScore[Const.Gap[gap]];
        if(this.checkYZY()){
            num += 1;
        }
        var guJiang = false;
        ExObject.eachKeyNum(this._huInfo.jiangs, function(c, n){
            var huInfo = {
                jiang: c
            };
            if(this.checkGuJiang(huInfo)){
                guJiang = true;
            }
        }.bind(this));
        if(guJiang){
            num += 1;
        }
        num += Const.ItemScore[Const.SanFeng[this.checkSanFeng()]];
        num += Const.ItemScore[Const.SanYuan[this.checkSanYuan()]];
        return num;
    },
    getColorNum: function(){
        var gap = this.checkGap();
        return gap.colorNum;
    },
    getMaxColorCardsNum: function(){
        var room = this.getRoom();
        var cards = this.getHandCards();
        var colors = room.getSubConfig().colors;
        var colorsNum = {};

        for (var i = 0, l = colors.length; i < l; ++i) {
            var color = colors[i];
            var colorCards = MJ.getColorCards(cards, color);

            if (MJ.isBasicColor(color)) {
                colorsNum[color] = ExObject.sumValue(colorCards);
            }
        }
        var maxNum = 0;
        ExObject.eachKeyNum(colorsNum, function(c, n){
            if(n > maxNum){
                maxNum = n;
            }
        });
        return maxNum;
    },

    getGap: function(){
        var gap = this.getColorNum();
        return 3 - gap;
    },
    //缺门/清一色/字一色
    checkGap: function(){
        var colors = {};

        ExObject.eachKeyNum(this._handCards.getCards(), function (card, num) {
            colors[MJ.getColor(card)] = 1;
        });

        if(this._stat.huCard){
            colors[MJ.getColor(this._stat.huCard)] = 1;

        }
        this._pengCards.forEach(function (card) {
            colors[MJ.getColor(card)] = 1;
        });

        this._chiCards.forEach(function (chiInfo) {
            colors[MJ.getColor(chiInfo.card)] = 1;
        });

        this._gangCards.forEach(function (gangInfo) {
            colors[MJ.getColor(gangInfo.card)] = 1;
        });
        var existColorZI = colors.hasOwnProperty(MJ.Color.ZI);
        if(existColorZI){
            delete colors[MJ.Color.ZI];
        }
        var colorNum = ExObject.count(colors);

        var results = {
            colorNum: colorNum,
            zi: existColorZI
        };

        return results;
    },
    //一张赢
    checkYZY: function(){
        var tingCards = this.getTingCards();
        if(tingCards.length == 1){
            return true;
        }else {
            return false;
        }
    },
    //三元
    checkSanYuan: function(ziCards){
        var cards = this.getHandCards();
        var colorCards = {};
        if(ziCards){
            colorCards = ziCards;
        }else{
            colorCards = MJ.getColorCards(cards, MJ.Color.ZI);
        }
        ExObject.eachKeyNum(colorCards, function (c, n) {
            if (c <= MJ.ZI.BF) {
                delete colorCards[c];
            }
        });
        var num = 233;
        var py = false;
        for(var i = MJ.ZI.HZ; i <= MJ.ZI.BB; i++){
            var n = colorCards[i];
            if(n){
                if(n > 0){
                    if(n < num){
                        num = n;
                    }
                }else{
                    py = true;
                    break;
                }
            }else {
                py = true;
                break;
            }
        }
        if(py){
            return 0;
        }
        return num;

    },
    //三风
    checkSanFeng: function(ziCards) {
        var cards = this.getHandCards();
        var colorCards = {};

        if(ziCards){
            colorCards = ziCards;
        }else{
            colorCards = MJ.getColorCards(cards, MJ.Color.ZI);
        }
        ExObject.eachKeyNum(colorCards, function (c, n) {
            if (c > MJ.ZI.BF) {
                delete colorCards[c];
            }
        });
        var num = 0;
        ExObject.eachKeyNum(colorCards, function (c, n) {
            if (n > 0) {
                var card = c;
                for(var i = 0; i < n; i++){
                    var newCards = clone(colorCards);
                    delete newCards[c];
                    var cardArr = [];
                    ExObject.eachKeyNum(newCards, function (c, n) {
                        if (n > 0) {
                            cardArr.push(c);
                        }
                    });
                    if(cardArr.length > 1){
                        for(var j = 0; j < cardArr.length; j++){
                            for (var l = 0; l < cardArr.length; l++){
                                if(colorCards[cardArr[j]] > colorCards[cardArr[l]]){
                                    var temp = cardArr[j];
                                    cardArr[j] = cardArr[l];
                                    cardArr[l] = temp;
                                }
                            }
                        }
                        colorCards[card] -= 1;
                        for(var j = 0; j < 2; j++){
                            colorCards[cardArr[j]] -= 1;
                        }
                        num += 1;
                    }else {
                        break;
                    }
                }
            }
        });
        return num;
    },
    //门清
    checkMenQing: function() {
        if (this._pengCards.length > 0) {
            return false;
        }
        if (this._chiCards.length > 0) {
            return false;
        }
        var isMenQing = true;
        this._gangCards.forEach(function (gangInfo) {
            if (gangInfo.gang == MJ.Gang.BA || gangInfo.gang == MJ.Gang.DIAN) {
                isMenQing = false;
            }
        }.bind(this));
        return isMenQing;
    },
    /**
     * 判断一条龙
     *
     */
    checkYTL: function(cards) {
        var isYTL = false;

        var colors = this.getRoom().getSubConfig().colors;
        colors.forEach(function(color) {
            if (this._checkColorYTL(color, MJ.getColorCards(cards, color))) {
                isYTL = true;
            }
        }.bind(this));

        return isYTL;
    },

    _checkColorYTL: function(color, colorCards) {
        if (ExObject.count(colorCards) != 9) {
            return false;
        }

        var isYTL = false;
        var colorMinCard = MJ.getValue(color, 1);
        var colorMaxCard = MJ.getValue(color, MJ.COLOR_CARD_NUM);
        var colorSplits = MJ.splitColorCards(colorMinCard, colorMaxCard, colorCards);
        colorSplits.forEach(function(items) {
            var itemCards = {};
            items.forEach(function(item) {
                if (item.length == 3) {
                    if (item[0] != item[1]) { //不是三张一样的牌
                        itemCards[item[0]] = 1;
                        itemCards[item[1]] = 1;
                        itemCards[item[2]] = 1;
                    }
                }
            });

            if (ExObject.count(itemCards) == 9) {
                isYTL = true;
            }
        });

        return isYTL;
    },
    //检测是否是庄家
    checkDealer: function(){
        var room = this.getRoom();
        if(this.getIndex() == room.getDealerIndex()){
            return true;
        }else {
            return false;
        }
    },
    //杠番
    checkGang: function(){
        this._stat.anGangCount = 0;
        this._stat.mingGangCount = 0;
        for (var i = 0, l = this._gangCards.length; i < l; ++i) {
            var gangInfo = this._gangCards[i];
            if (gangInfo.gang == MJ.Gang.AN || gangInfo.gang == MJ.Gang.ANS) {
                this._stat.anGangCount++;
            } else {
                this._stat.mingGangCount++;
            }
        }
    },
    getGangFan: function(){
        this.checkGang();
        var gang = 0;
        gang += this._stat.mingGangCount;
        gang += this._stat.anGangCount * 2;
        return gang;
    },
    //孤将
    checkGuJiang: function(huInfo){
        if(huInfo.pattern == Const.Pattern.PAIR7){
            return false;
        }
        var color = MJ.getColor(huInfo.jiang);
        if(MJ.isBasicColor(color) == false){
            return false;
        }
        var colors = {};

        this._pengCards.forEach(function (card) {
            colors[MJ.getColor(card)] = 1;
        });

        this._chiCards.forEach(function (chiInfo) {
            colors[MJ.getColor(chiInfo.card)] = 1;
        });

        this._gangCards.forEach(function (gangInfo) {
            colors[MJ.getColor(gangInfo.card)] = 1;
        });
        var colorCards = MJ.getColorCards(this.getHandCards(), color);

        if(ExObject.sumValue(colorCards) == 2){
            if(colors[color]){
                return false;
            }else {
                return true;
            }
        }else{
            return false;
        }
    }


});